using System.Collections;
using UnityEngine;

public class ResultUI_level_win : MonoBehaviour
{
	private GameObject resultobj;

	public UIEventListener mainbtn;

	public UIEventListener nextbtn;

	public UILabel timelabel;

	public UILabel[] taskstarlabel;

	public UISprite[] starflag;

	public UISprite[] upstarflag;

	private bool[] starshowflag = new bool[3];

	public UILabel explabel;

	public UILabel moneylabel;

	public Transform[] fixobj;

	public GameObject[] getobj;

	public Piece_item[] getpiece;

	private GameLevel curgamelevel_info;

	public UISlider expslider;

	public UISprite currankflag;

	public UISprite nextrankflag;

	public UILabel exp_label;

	private float curexp;

	private float rateexp;

	private int endexp;

	private bool exprunflag;

	public UIWidget ratewi;

	//public Animation scaleanima;
	public Animator animator;

	public UIEventListener rateyesbtn;

	public UIEventListener rateclosebtn;

	public UIWidget colliderwi;

	private bool poprankui;

	private int firstlevel;

	private bool temp_first;

	private bool isshowrate;

	private void Start()
	{
		mainbtn.onClick = OnClickmainBtn;
		nextbtn.onClick = OnClicknextBtn;
		rateyesbtn.onClick = OnClickrateyesBtn;
		rateclosebtn.onClick = OnClickratecloseBtn;
	}

	private void Update()
	{
		if (exprunflag)
		{
			if (curexp < (float)endexp)
			{
				curexp += Time.deltaTime * rateexp;
			}
			else
			{
				curexp = endexp;
				exprunflag = false;
			}
			expshow((int)curexp);
		}
	}

	public void starstep(int step)
	{
		if (starshowflag[step])
		{
			starshowflag[step] = false;
			upstarflag[step].enabled = true;
		}
	}

	private IEnumerator ShowStar()
	{
		for (int k = 0; k < 3; k++)
		{
			for (float i = 0f; i < 0.3f; i += Time.deltaTime)
			{
				yield return 0;
			}
			if (starshowflag[k])
			{
				starshowflag[k] = false;
				upstarflag[k].enabled = true;
				MonoInstance<AudioController>.instance.play(AudioType.UI_star, 0f);
			}
		}
		for (float j = 0f; j < 0.3f; j += Time.deltaTime)
		{
			yield return 0;
		}
		colliderwi.alpha = 0f; colliderwi.gameObject.SetActive(false);
		/* if (GamePlayerprefs.instance.showrate == 0)
		{
			showrate();
			gamebackctl.instance.ChangeGameUIstate(GameUIState.rate);
			GamePlayerprefs.instance.setrate();
		}
		else
		{ */
		Platform.ShowFeatureView();
		Platform.ShowFullScreenSmall();
		//}
	}

	public void enable()
	{
		if (resultobj == null)
		{
			resultobj = base.gameObject;
		}
		NGUITools.SetActive(resultobj, state: true);
		StartCoroutine("ShowStar");
		init_ui_info();
		MonoInstance<AudioController>.instance.play(AudioType.UI_gameover_suc, 0f);
		colliderwi.alpha = 1f; colliderwi.gameObject.SetActive(true);
	}

	public void init_ui_info()
	{
		levelinfoshow();
		saveAchi();
	}

	public void saveAchi()
	{
		GamePlayerprefs.instance.readachievement();
		GamePlayerprefs.instance.readdailytask();
		GamePlayerprefs.instance.savefightinfo();
		GamePlayerprefs.instance.savedailytask(1);
	}

	public void levelinfoshow()
	{
		bool[] array = TasksController.instance.check_star();
		if (GlobalInf.gamefirst)
		{
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = true;
			}
			if (TasksController.instance.alltime > 300f)
			{
				timelabel.text = MyMath.TimeSet(280f);
			}
			else
			{
				timelabel.text = MyMath.TimeSet(TasksController.instance.alltime);
			}
			GamePlayerprefs.instance.set_popsaleflag();
		}
		else
		{
			timelabel.text = MyMath.TimeSet(TasksController.instance.alltime);
		}
		int num = 0;
		for (int j = 0; j < 3; j++)
		{
			if (array[j])
			{
				num++;
			}
		}
		for (int k = 0; k < 3; k++)
		{
			if (k < num)
			{
				starshowflag[k] = true;
			}
			else
			{
				starshowflag[k] = false;
			}
		}
		LevelStar levelStar = new LevelStar();
		for (int l = 0; l < 3; l++)
		{
			levelStar = TasksController.instance.StarList[l];
			taskstarlabel[l].text = l + 1 + ". ";
			switch (levelStar.type)
			{
				case 1:
					taskstarlabel[l].text += "完成关卡";
					break;
				case 2:
					{
						UILabel obj2 = taskstarlabel[l];
						string text = obj2.text;
						obj2.text = text + "至少 " + levelStar.sontype + "% 血量";
						break;
					}
				case 3:
					switch (levelStar.sontype)
					{
						case 0:
							taskstarlabel[l].text += "击败所有敌人";
							break;
						case 1:
							taskstarlabel[l].text += "击落所有战斗机";
							break;
						case 2:
							taskstarlabel[l].text += "摧毁所有建筑";
							break;
						case 3:
							taskstarlabel[l].text += "击沉所有战舰";
							break;
					}
					break;
				case 4:
					switch (levelStar.sontype)
					{
						case 0:
							taskstarlabel[l].text += "保护所有友方单位";
							break;
						case 1:
							taskstarlabel[l].text += "保护所有友方战斗机";
							break;
						case 2:
							taskstarlabel[l].text += "保护所有友方建筑";
							break;
						case 3:
							taskstarlabel[l].text += "保护所有友方战舰";
							break;
					}
					break;
				case 5:
					{
						UILabel obj = taskstarlabel[l];
						string text = obj.text;
						obj.text = text + "在 " + levelStar.sontype / 60 + " 分钟内完成关卡";
						break;
					}
				case 6:
					taskstarlabel[l].text += "潜在任务成功";
					break;
				case 7:
					taskstarlabel[l].text += "成功完成速度竞赛";
					break;
			}
			if (array[l])
			{
				starflag[l].enabled = true;
			}
			else
			{
				starflag[l].enabled = false;
			}
		}
		curgamelevel_info = TasksController.instance.curgamelevel;
		explabel.text = string.Empty + curgamelevel_info.success_exp;
		moneylabel.text = string.Empty + curgamelevel_info.success_gold;
		curexp = GamePlayerprefs.instance.allexp;
		endexp = (int)curexp + curgamelevel_info.success_exp;
		rateexp = (float)curgamelevel_info.success_exp / 2f;
		expshow((int)curexp);
		exprunflag = true;
		int num2 = 0;
		for (int m = 0; m < 2; m++)
		{
			if (curgamelevel_info.dropitem[m].dropid != -1)
			{
				if (UnityEngine.Random.Range(1, 101) <= curgamelevel_info.dropitem[m].gailv)
				{
					GamePlayerprefs.instance.readpiece();
					PieceData pieceData = DataController.instance.Getpiece(curgamelevel_info.dropitem[m].dropid);
					getpiece[m].enable(pieceData);
					GamePlayerprefs.instance.addpiece(pieceData.id, 1);
					num2++;
				}
				else
				{
					NGUITools.SetActive(getobj[m], state: false);
				}
			}
			else
			{
				NGUITools.SetActive(getobj[m], state: false);
			}
		}
		switch (num2)
		{
			case 0:
				fixobj[0].transform.localPosition = new Vector3(-30f, -18f, 0f);
				fixobj[1].transform.localPosition = new Vector3(30f, -18f, 0f);
				break;
			case 1:
				fixobj[0].transform.localPosition = new Vector3(-60f, -18f, 0f);
				fixobj[1].transform.localPosition = new Vector3(0f, -18f, 0f);
				if (UnityVersionUtil.IsActive(getobj[0]))
				{
					getobj[0].transform.localPosition = new Vector3(60f, -18f, 0f);
				}
				else
				{
					getobj[1].transform.localPosition = new Vector3(60f, -18f, 0f);
				}
				break;
		}
		Platform.flurryEvent_level(GlobalInf.CurrentLevel, 5 + num);
		GamePlayerprefs.instance.save_level_info(array);
		GamePlayerprefs.instance.add_exp(curgamelevel_info.success_exp);
		GamePlayerprefs.instance.add_money(curgamelevel_info.success_gold);
	}

	public void expshow(int expnum)
	{
		expdata exp = GamePlayerprefs.instance.GetExp(expnum);
		if (exp.level >= 19)
		{
			expslider.value = 1f;
			exp_label.text = string.Empty;
			currankflag.spriteName = "19." + GamePlayerprefs.instance.ranknameImage[exp.level - 1];
			nextrankflag.enabled = false;
			currankflag.SetDimensions(56, 48);
			nextrankflag.SetDimensions(56, 48);
		}
		else
		{
			expslider.value = (float)exp.curexp / (float)exp.maxexp;
			exp_label.text = string.Empty + exp.curexp + "/" + exp.maxexp;
			currankflag.spriteName = string.Empty + exp.level + "." + GamePlayerprefs.instance.ranknameImage[exp.level - 1];
			nextrankflag.spriteName = string.Empty + (exp.level + 1) + "." + GamePlayerprefs.instance.ranknameImage[exp.level];
			if (exp.level >= 15)
			{
				currankflag.SetDimensions(56, 48);
				nextrankflag.SetDimensions(56, 48);
			}
			else if (exp.level < 14)
			{
				currankflag.SetDimensions(40, 44);
				nextrankflag.SetDimensions(40, 44);
			}
			if (exp.level == 14)
			{
				currankflag.SetDimensions(40, 44);
				nextrankflag.SetDimensions(56, 48);
			}
		}
		showrankeui(exp.level);
	}

	public void showrankeui(int level)
	{
		if (!poprankui && !isshowrate)
		{
			if (!temp_first)
			{
				firstlevel = level;
				temp_first = true;
			}
			if (level == firstlevel + 1)
			{
				GameUIController.instance.enable_rankui();
				poprankui = true;
			}
		}
	}

	public void OnClickmainBtn(GameObject btn)
	{
		Platform.HideFeatureView();
		MenuUIController.beginshow = BeginShow.main;
		Time.timeScale = 1f;
		UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
		MidLoading.loadlevel = 0;
	}

	public void OnClicknextBtn(GameObject btn)
	{
		Platform.HideFeatureView();
		MenuUIController.beginshow = BeginShow.level;
		Time.timeScale = 1f;
		UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
		MidLoading.loadlevel = 0;
	}

	public void showrate()
	{
		//isshowrate = true;
		//ratewi.alpha = 1f; ratewi.gameObject.SetActive(true);
		//scaleanima.Stop();
		//animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
		//Invoke("animplay", Time.deltaTime * 2f);
	}

	public void OnClickrateyesBtn(GameObject btn)
	{
		//ratewi.alpha = 0f; ratewi.gameObject.SetActive(false);
		gamebackctl.instance.BackGameUIstate();
		Platform.flurryEvent_guide_rate();
		Platform.Rating();
	}

	public void OnClickratecloseBtn(GameObject btn)
	{
		//ratewi.alpha = 0f; ratewi.gameObject.SetActive(false);
		gamebackctl.instance.BackGameUIstate();
	}

	public void animplay()
	{
		/* scaleanima["PopWinAnimation"].time = 0f;
		scaleanima["PopWinAnimation"].speed = 1f;
		scaleanima.Play(); */
		animator.SetTrigger("popWin1");
	}

	public void dis_rate()
	{
		//ratewi.alpha = 0f; ratewi.gameObject.SetActive(false);
		gamebackctl.instance.BackGameUIstate();
	}

	public void disable()
	{
		NGUITools.SetActive(resultobj, state: false);
	}
}
